<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragment::top">

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="common/fragment::leftmenu"></div>
        <!--End 左侧导航-->

        <!--头部信息-->
        <div th:replace="common/fragment::header"></div>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                            <div >
                                <form action="#!" class="horizontal " id="add-user-form" method="post">

                                    <!--商品名-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="goodname" style="text-align: center;line-height: 36px">名称</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="goodname" name="goodname"
                                                   placeholder="商品名" type="text">
                                        </div>
                                    </div>
                                    <!--商品规格-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="spec" style="text-align: center;line-height: 36px">商品规格</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="spec" name="spec"
                                                   placeholder="商品规格" type="text">
                                        </div>
                                    </div>
                                    <!--包装-->
<!--                                    <div class="form-group col-md-10 ">-->
<!--                                        <label class="col-md-2 control-label" for="pk" style="text-align: center;line-height: 36px">包装</label>-->
<!--                                        <div class="col-md-8">-->
<!--                                            <input class="form-control" id="pk" name="pk"-->
<!--                                                   placeholder="包装" type="text">-->
<!--                                        </div>-->
<!--                                    </div>-->
                                    <!--计量单位-->
                                    <

                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="unit" style="text-align: center;line-height: 36px">计量单位</label>
                                        <div class="col-md-8">
                                            <select class="form-control" id="unit" name="unit" size="1" >
                                                <option th:each="v:${unitvalue}"  th:value="${v}" th:text="${unitname[v]}">请选择</option>

                                            </select>
                                        </div>
                                    </div>
                                    <!--商品价格-->
<!--                                    <div class="form-group col-md-10 ">-->
<!--                                        <label class="col-md-2 control-label" for="price" style="text-align: center;line-height: 36px">商品价格</label>-->
<!--                                        <div class="col-md-8">-->
<!--                                            <input class="form-control" id="price" name="price"-->
<!--                                                   placeholder="商品价格" type="text">-->
<!--                                        </div>-->
<!--                                    </div>-->

                                    <!--商品状态-->
                                    <div class="form-group  col-md-10">
                                        <label class="col-md-2 control-label" for="status" style="text-align: center;line-height: 36px">状态</label>
                                        <div class="col-md-8">
                                            <label class="lyear-switch switch-solid switch-primary">
                                                <input checked="" id="status" name="status" type="checkbox">
                                                <span></span>
                                            </label>
                                        </div>
                                    </div>
                                    <!--商品注释-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="comment" style="text-align: center;line-height: 36px">备注</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="comment" name="comment"
                                                   placeholder=".....备注....."  type="text">
                                        </div>
                                    </div>




                                    <div class="form-group col-md-10">
                                        <button
                                                class="btn btn-primary ajax-post col-md-2"
                                                id="add-good-btn"
                                                target-form="add-form"
                                                type="button">确 定
                                        </button>
                                        <button
                                                class="btn btn-default col-md-2"
                                                onclick="history.back(-1);return false;"
                                                type="button">返 回
                                        </button>
                                    </div>
                                </form>
                            </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<div th:insert="common/fragment::tail-script"></div>

<script type="text/javascript">
    $(function () {
// 商品单元数组
        let goodunit = ["散装", "包", "公斤", "吨", "件", "套"]

        // 添加good按钮提交 - addgood.ajax
        $('#add-good-btn').on('click', function () {



            let goodname = $('#goodname').val();
            let spec = $('#spec').val();
            // let pk = $('#pk').val();
            let unit = $('#unit').val();
            unit = goodunit[unit]
            let comment = $('#comment').val();
            let status =$('input[name=goodstatus]:checked').val()

            // if(status === 'on'){
            //     status = 1
            // }else{
            //     status = -1
            // }

            if(goodname===''){
                    confirmMsg('请填写商品名称')
                    return
            }

            if(spec===''){
                confirmMsg('请填写商品规格')
                return
            }


            //生成data -- json

            let data = {
                name : goodname,
                spec:spec,
                unit: unit,
                status: status,
                comment: comment
            }
            //   let data = $('#icon-form').serialize()
            post_ajax('/good/addgood.ajax', data, '/good/goodlist.do');

        });

        // 页面 禁用按钮 -- 提交后台 切换状态为禁用


    });
</script>
</body>
</html>